/*
 * MainGame.cpp
 *
 *  Created on: May 2, 2011
 *      Author: default
 */

#include <iostream>
#include "MainGame.h"
#include "Money.h"

using namespace std;

#define ADD_Money_H 170
#define ADD_Money_W 40

const int add_Money_x = 565;
const int add_Money_y = 787;

#define ALL_LEVEL_H 260
#define ALL_LEVEL_W 22

const int level_x = 23;
const int level_y = 732;


static const int MoneyTEXT_Y = 940;

bool MainGame::init(){

	m_Screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);

	if( m_Screen == NULL ) {
		return false;
	}

	SDL_WM_SetCaption( "POKER", NULL );

	eState = eIntro;
	m_LevelDraw = false;
	m_Background = load_image("backgrounds/screen.png");
	m_Cash = load_image("backgrounds/cash.png");
	m_Win = load_image("backgrounds/win.png");
	m_Bet = load_image("backgrounds/bet.png");

	gMoney.init();
	gLevel.init();
	return true;
}

void MainGame::onClick(int nX, int nY){

	if (nX > add_Money_x && nX < (add_Money_x + ADD_Money_H) &&
			nY > add_Money_y && nY < (add_Money_y + ADD_Money_W) )
	{
		gMoney.ChangeMoney();
	}

	if (nX > level_x && nX < (level_x + ALL_LEVEL_H) &&
			nY > level_y && nY < (level_y + ALL_LEVEL_W) )
	{
		gLevel.LevelClick(nX, nY);
	}

}

void MainGame::onDrawBackground(){

	apply_surface(0, 0, m_Background, m_Screen);
	apply_surface(300, MoneyTEXT_Y, m_Cash, m_Screen);
	apply_surface(800, MoneyTEXT_Y, m_Win, m_Screen);
	apply_surface(580, MoneyTEXT_Y, m_Bet, m_Screen);

}

void MainGame::onDraw(){

		onDrawBackground();
		gMoney.onDraw();

		gLevel.onDraw();

	if( SDL_Flip( m_Screen ) != 0 )
	{
		cout << "Error";
	}
}

MainGame gMainGame;
